package sjjg.graph;

import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class WeightDirGraph {
      private int V;
      private int E;
      private Queue<DirectedEdge>[]adj;

    public WeightDirGraph(int V) {
           this.V=V;
           E=0;
           adj=new LinkedBlockingQueue[V];
        for (int i = 0; i < adj.length; i++) {
             adj[i]=new LinkedBlockingQueue<>();
        }
    }
    public int V(){
         return V;
    }
    public int E(){
        return E;
    }
    public void addEdge(DirectedEdge directedEdge){
           adj[directedEdge.from()].add(directedEdge);
           E++;
    }
    public Queue<DirectedEdge>adj(int v){
           return adj[v];
    }
    public Queue<DirectedEdge> edges(){
           //遍历邻接表
           Queue<DirectedEdge>edges=new LinkedBlockingQueue();
        for (int i = 0; i < adj.length; i++) {
            for (DirectedEdge directedEdge : adj[i]) {
                 if(directedEdge!=null){
                      edges.add(directedEdge);
                 }
            }
        }
        return edges;
    }
}
